package com.sgb.kjwl.view.ui.activity.self;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.amap.api.maps.model.LatLng;
import com.sgb.alimaplibrary.widget.MapMarkerView;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityGetPositionBinding;
import com.sgb.kjwl.databinding.ActivityMapPositionBinding;
import com.sgb.kjwl.model.entity.supplier3.SupplierEntity3;
import com.sgb.kjwl.view.widget.map.GetMapInfoPop;
import com.sgb.kjwl.view.widget.pick.MapAppWindow;
import com.sgb.kjwl.view.widget.pick.PickMapAppWindow;
import com.sgb.link.router.PathUser;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.util.MToast;

import java.util.List;


/**
 * @author: 王彬臣
 * @date: 2021/7/20
 * @Description: 招商引资地图查看
 */
@Route(path = PathUser.MapPositionActivity)
public class MapPositionActivity extends AppActivity {
    private ActivityMapPositionBinding binding;
    @Autowired(name = "latitude")
    Double currentLat=0.0;
    @Autowired(name = "longitude")
    Double currentLong=0.0;
    @Autowired(name = "address")
    String address = "";
    @Autowired(name = "companyName")
    String companyName = "";

    private List<SupplierEntity3> mapSupplierList;

    private GetMapInfoPop getMapInfoPop;
    private MapAppWindow pickMapAppWindow;
    private boolean isShowBaidu=true;
    private boolean isShowGaode=true;
    private boolean isShowTenxun=false;



    @Override
    protected void setupActivityComponent(AppComponent appComponent) {

    }

    @Override
    protected boolean statusBarDark() {
        return true;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ARouter.getInstance().inject(this);
        initMap(savedInstanceState);
        initPoiSearch();
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(MapPositionActivity.this, R.layout.activity_map_position);
        binding.include.ivBack.setVisibility(View.VISIBLE);
        binding.include.ivBack.setOnClickListener(v -> finish());
        binding.include.rightView.setVisibility(View.GONE);
        binding.include.titleView.setText("查看地图");
    }

    @Override
    protected void init() {

    }

    private void initMap(Bundle savedInstanceState) {
        binding.mapView.initMap(savedInstanceState, getLifecycle(), new MapMarkerView.CallBack() {
            @Override
            public void onMarkerClick(int pos, String title) {

            }

            @Override
            public void onLocation(Double Lat, Double Log, String string) {

            }

            @Override
            public void getAddress(Double Lat, Double Log, String address) {
                super.getAddress(Lat, Log, address);
            }

            @Override
            public void onRegeocodeSearched(Double Lat, Double Log, String string) {
                super.onRegeocodeSearched(Lat, Log, string);

            }
        });
    }

    private void initPoiSearch() {
        if (currentLat != 0 && currentLong != 0) {
            LatLng latLng = new LatLng(currentLat, currentLong);
            binding.mapView.setMyLocation(currentLat, currentLong, R.mipmap.parcker_map_position);
            binding.mapView.getLatLotExtra(currentLat, currentLong);
            binding.companyName.setText(companyName);
            binding.currentPosition.setText(address);
            binding.goButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showHintDialog(MapPositionActivity.this);
                }
            });
        }
    }

    protected void showHintDialog(Context context) {
        showPopwindow(isShowBaidu, isShowGaode, isShowTenxun);
    }

    protected void showPopwindow(boolean showBaidu, boolean showGaode, boolean showTenxun) {
        pickMapAppWindow = new MapAppWindow(getActivity(), 3);
        pickMapAppWindow.setBgView(binding.grayLayout);
        pickMapAppWindow.showPopwindowBottom(binding.mapView);
        pickMapAppWindow.setData(currentLat, currentLong, address);
        pickMapAppWindow.setShowData(showBaidu, showGaode, showTenxun);
    }


}
